const IPCIDR = require("ip-cidr");
const IPCIDRList = require("./ip.json");
var { TestIP } = require("./scan");

function wait(ms) {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve()
        }, ms)
    });
};

async function main(hostName) {
    let available_ip = []
    for (let i = 0; i < IPCIDRList.Azure.KR.length; i++) {
        if (available_ip.length > 5) {
            break
        }
        let krcidr = new IPCIDR(IPCIDRList.Azure.KR[i]);
        let temp = krcidr.toArray()
        //256 /24 max
        for (let j = 0; j < temp.length && j < 256; j++) {
            if (available_ip.length > 5) {
                break
            }
            TestIP(temp[j], hostName).then((result) => {
                // console.log(temp[j],result)
                if (result)
                    available_ip.push(temp[j])
            })
        }
        await wait(4000);
        console.log(available_ip)
    }
}

const targetHost = "cdnjp.hkix.me"
if (targetHost == "") {
    console.error("hostname写一下")
} else {
    main(targetHost)
}
